import { Md5 } from 'ts-md5'
import CryptoJS from 'crypto-js'
export const md5 = (text: string): string => {
  const md5: any = new Md5()
  md5.appendAsciiStr(text)
  return md5.end()
}

export const EncryptB64 = (textString: string) => {
  try {
    var wordArray = CryptoJS.enc.Utf8.parse(textString)
    var encrypted = CryptoJS.enc.Base64.stringify(wordArray)
    return encrypted.toString()
  } catch (e) {
    return textString
  }
}

export const DecryptB64 = (textString: string) => {
  try {
    var words = CryptoJS.enc.Base64.parse(textString)
    return words.toString(CryptoJS.enc.Utf8)
  } catch (e) {
    console.error(e)
    return textString
  }
}
